package com.hentai.androidserver.controller;

import com.hentai.androidserver.domain.Phone;
import com.hentai.androidserver.service.PhoneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/phone")
public class PhoneController {

    @Resource
    PhoneService phoneService;

    @GetMapping(value = "/p/{uid}")
    public List<Phone> getPhoneList(@PathVariable Integer uid) {
        log.info("{}", uid);

        if (uid <= 0) {
            return null;
        }
        List<Phone> phones = phoneService.queryByUserId(uid);

        log.info("{}", phones);

        return phones;
    }

    @PutMapping("/upload")
    public List<Phone> uploadPhoneMessage(@RequestBody List<Phone> phones) {
        System.out.println(phones);
        List<Phone> tarPhones = phoneService.makeChangeFromMobile(phones);
        if (tarPhones == null) {
            return new ArrayList<>();
        }
        return tarPhones;
    }

}
